package com.tally.project.system.billing.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.tally.project.system.billing.domain.Billing;
import com.tally.project.system.category.domain.Category;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @Author soul
 * @Date 2023/9/20 20:00
 * @Description
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BillingVo implements Serializable {
    /** ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    /** 分类ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long categoryId;
    /** 分类名称 */
    private String name;
    /** 分类图标 */
    private String icon;
    /** 类型 */
    private Integer type;
    /** 备注 */
    private String remark;
    /** 图片 */
    private String image;
    /** 金额 */
    private BigDecimal amount;
    /** 周几 */
    private String week;
    /** 时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime date;
    /** 天数 */
    private Integer day;

    public BillingVo(Billing billing, Map<Long, Category> categoryMap) {
        Category category = categoryMap.get(billing.getCategoryId());
        this.id = billing.getId();
        this.categoryId = billing.getCategoryId();
        this.name = category == null ? "" : category.getName();
        this.icon = category == null ? "" : category.getIcon();
        this.type = billing.getType();
        this.remark = billing.getRemark();
        this.image = billing.getImage();
        this.amount = billing.getAmount();
        this.week = billing.getWeek();
        this.date = billing.getDate();
        this.day = billing.getDay();
    }
}
